#include <stdio.h>

const char str[3] = {'J', 'C', 'B'};

int getSum(int data[]){
	int sum = 0;
	for(int i = 0;i < 3; i++){
		sum += data[i];
	}
	return sum;
}

void  printMax(int data[]){
	int maxId = 0, minId = 0;
	int max = -1, min = 0x3f3f3f;
	for(int i = 0; i < 3; i++){
		if(data[i] >= max){
			maxId = i;
			max = data[i];
			continue;
		}
		if(data[i] <= min){
			minId = i;
			min = data[i];
		}
	}
	printf("%c %c\n", str[maxId], str[(minId==2)?0:(minId+1)]);
}

int main()
{
	int i = 0, E = 0,N = 0, aWinNum = 0;
	char A[1024] = {0};
	char B[1024] = {0};
	int output1[3] = {0};

	scanf("%d", &N);
	for(; i < N; i++){
		scanf("%s %s", &A[i], &B[i]);
	}

	for(i = 0; i < N; i++){
		if(A[i] == B[i]){
			E++;
		}
		else if(A[i] == 'J' && B[i] == 'B'){
			output1[0]++;
		}
		else if(A[i] == 'C' && B[i] == 'J'){
			output1[1]++;
		}
		else if(A[i] == 'B' && B[i] == 'C'){
			output1[2]++;
		}
		else{
			continue;
		}
	}
	printf("\n");
	aWinNum = getSum(output1);
	printf("%d %d %d\n", aWinNum, E, N - aWinNum - E);
	printf("%d %d %d\n", N - aWinNum - E, E, aWinNum);
	printMax(output1);
	return 0;
}
